package com.lxmes.pm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.pm.domain.ABook;
import com.lxmes.pm.service.IABookService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 著作管理Controller
 * 
 * @author zhangzhiyu
 * @date 2023-04-04
 */
@RestController
@RequestMapping("/pm/aBook")
public class ABookController extends BaseController
{
    @Autowired
    private IABookService aBookService;

    /**
     * 查询著作管理列表
     */
    @PreAuthorize("@ss.hasPermi('pm:aBook:list')")
    @GetMapping("/list")
    public TableDataInfo list(ABook aBook)
    {
        startPage();
        List<ABook> list = aBookService.selectABookList(aBook);
        return getDataTable(list);
    }

    /**
     * 导出著作管理列表
     */
    @PreAuthorize("@ss.hasPermi('pm:aBook:export')")
    @Log(title = "著作管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ABook aBook)
    {
        List<ABook> list = aBookService.selectABookList(aBook);
        ExcelUtil<ABook> util = new ExcelUtil<ABook>(ABook.class);
        util.exportExcel(response, list, "著作管理数据");
    }

    /**
     * 获取著作管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('pm:aBook:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(aBookService.selectABookById(id));
    }

    /**
     * 新增著作管理
     */
    @PreAuthorize("@ss.hasPermi('pm:aBook:add')")
    @Log(title = "著作管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ABook aBook)
    {
        return toAjax(aBookService.insertABook(aBook));
    }

    /**
     * 修改著作管理
     */
    @PreAuthorize("@ss.hasPermi('pm:aBook:edit')")
    @Log(title = "著作管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ABook aBook)
    {
        return toAjax(aBookService.updateABook(aBook));
    }

    /**
     * 删除著作管理
     */
    @PreAuthorize("@ss.hasPermi('pm:aBook:remove')")
    @Log(title = "著作管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aBookService.deleteABookByIds(ids));
    }
}
